<%--                                                                       --%>
<%-- Copyright (c) 2005 BroadVision, Inc.  All rights reserved.            --%>
<%--                                                                       --%>
<%-- This software is copyrighted. Under the copyright laws, this software --%>
<%-- may not be copied, in whole or in part, without prior written consent --%>
<%-- of BroadVision, Inc. or its assignees. This software is provided      --%>
<%-- under the terms of a license between BroadVision and the recipient,   --%>
<%-- and its use is subject to the terms of that license.                  --%>
<%--                                                                       --%>
<%-- This software may be protected by one or more U.S. and International  --%>
<%-- patents.  Certain applications of BroadVision One-To-One software are --%>
<%-- covered by U.S. patent 5,710,887.                                     --%>
<%--                                                                       --%>
<%-- TRADEMARKS: BroadVision and BroadVision One-To-One are registered     --%>
<%-- trademarks of BroadVision, Inc., in the United States and the         --%>
<%-- European Community, and are trademarks of BroadVision, Inc., in other --%>
<%-- countries.  The BroadVision logo, is a trademark of BroadVision,      --%>
<%-- Inc., in the United States and other countries. Additionally, IONA    --%>
<%-- and Orbix are trademarks of IONA Technologies, Ltd.  RSA, MD5, and    --%>
<%-- RC2 are trademarks of RSA Data Security, Inc.                         --%>
<%--                                                                       --%>

<%@ taglib uri="/WEB-INF/c.tld" prefix="c" %>
<%@ taglib uri="/WEB-INF/struts-html-el.tld" prefix="html-el" %>
<%@ taglib uri="/WEB-INF/struts-bean-el.tld" prefix="bean-el" %>

<script language="JavaScript">

//
//
//
function onChangeSrcContentType() {
<c:if test="${epProgramPresentationForm.map.id == 0}">
  document.epProgramPresentationForm.action = "<c:url value="/ep/programPresentationNew.do"/>";
</c:if>
<c:if test="${epProgramPresentationForm.map.id != 0}">
  document.epProgramPresentationForm.action = "<c:url value="/ep/programPresentationEdit.do"/>";
</c:if>
  document.epProgramPresentationForm.srcContentTypeChanged.value = 1;
  document.epProgramPresentationForm.submit();
}

//
//
//
function onChangeSrcType() {
<c:if test="${epProgramPresentationForm.map.id == 0}">
  document.epProgramPresentationForm.action = "<c:url value="/ep/programPresentationNew.do"/>";
</c:if>
<c:if test="${epProgramPresentationForm.map.id != 0}">
  document.epProgramPresentationForm.action = "<c:url value="/ep/programPresentationEdit.do"/>";
</c:if>
  document.epProgramPresentationForm.submit();
}

//
//
//
function doSrcCategorySelect() {
  doPickerPopupAction('<c:url value="/mt/categoryPickerPopup.do"/>', 'setSrcCategory', 
    <c:out value="${epProgramPresentationForm.map.srcContentType}"/>, null, null, null, 
    true, true, false, null, null, null, false);
}

//
//
//
function setSrcCategory(ids, names) {
  document.epProgramPresentationForm.srcId.value = ids[0];
  document.epProgramPresentationForm.srcName.value = names[0];
}

//
//
//
function doSrcContentSelect() {
  doPickerPopupAction('<c:url value="/mt/pickerPopupUncategorized.do"/>', 'setSrcContent', 
    <c:out value="${epProgramPresentationForm.map.srcContentType}"/>, null, null);
}

//
//
//
function setSrcContent(ids, names) {
  document.epProgramPresentationForm.srcId.value = ids[0];
  document.epProgramPresentationForm.srcName.value = names[0];
}

//
//
//
function doPublishCategorySelect() {
  doPickerPopupAction('<c:url value="/mt/categoryPickerPopup.do"/>', 'setPublishCategory', 
    <c:out value="${epProgramPresentationForm.map.srcContentType}"/>, null, null, null,
    true, true, false, null, null, null, false);
}

//
//
//
function setPublishCategory(ids, names) {
  document.epProgramPresentationForm.publishCategoryId.value = ids[0];
  document.epProgramPresentationForm.publishCategoryName.value = names[0];
}

//
//
//
function doProcessSelect() {
  doPickerPopupAction('<c:url value="/ep/publishingProcessPickerPopup.do"/>', 'setPublishProcess', 
    <c:out value="${epProgramPresentationForm.map.srcContentType}"/>, null, null, null, false, false, false);
}

//
//
//
function setPublishProcess(ids, names) {
  document.epProgramPresentationForm.processOID.value = ids[0];
  document.epProgramPresentationForm.pubProcessName.value = names[0];
}

//
//
//
function doRulesetSelect() {
  doPickerPopupAction('<c:url value="/mt/pickerPopupUncategorized.do"/>', 'setSrcRuleset', 
    53, null, null, null, false, true, true, "com.broadvision.portal.tools.action.program.ProgramRulesetPickerFilter", 
    null, null, null, "<c:out value="${epProgramPresentationForm.map.srcContentType}"/>", null, false, true);
}

//
//
//
function setSrcRuleset(ids, names) {
  document.epProgramPresentationForm.srcId.value = ids[0];
  document.epProgramPresentationForm.srcName.value = names[0];
}

//
//
//
function selectJspPopup() {
  jspScriptPickerPopup('setSelectedJsp');
}
  
//
//
//
function setSelectedJsp(jspPath) {
  document.epProgramPresentationForm.scriptPath.value = jspPath;
}

//
//
//
function selectBlockJspPopup() {
  jspScriptPickerPopup('setSelectedBlockJsp');
}
  
//
//
//
function setSelectedBlockJsp(jspPath) {
  document.epProgramPresentationForm.embedScriptPath.value = jspPath;
}

//
//
//
function validateForm(form) {
<c:if test="${epProgramPresentationForm.map.srcType == 0}">
  <c:set var="argName"><bean-el:message key="ep.program.source.type.ruleset" bundle="ep.messages"/></c:set>
  var srcId = form.srcId.value;
  if (srcId == "0") {
    alert("<bean-el:message key="errors.required" arg0="${argName}"/>");
    return false;
  }
</c:if>
<c:if test="${epProgramPresentationForm.map.srcType == 1 || epProgramPresentationForm.map.srcType == 6}">
  <c:set var="argName"><bean-el:message key="ep.category" bundle="ep.messages"/></c:set>
  var srcId = form.srcId.value;
  if (srcId == "0") {
    alert("<bean-el:message key="errors.required" arg0="${argName}"/>");
    return false;
  }
</c:if>
<c:if test="${epProgramPresentationForm.map.srcType == 2}">
  <c:set var="argName"><bean-el:message key="ep.program.source.type.content" bundle="ep.messages"/></c:set>
  var srcId = form.srcId.value;
  if (srcId == "0") {
    alert("<bean-el:message key="errors.required" arg0="${argName}"/>");
    return false;
  }
</c:if>
<c:if test="${epProgramPresentationForm.map.srcType == 3}">
  <c:set var="argName"><bean-el:message key="ep.program.page.script.path" bundle="ep.messages"/></c:set>
  var s = form.scriptPath.value;
  var scriptPath = s.stringTrim();
  if (scriptPath == "") {
    alert("<bean-el:message key="errors.required" arg0="${argName}"/>");
    return false;
  }
  <c:set var="argName"><bean-el:message key="ep.program.block.script.path" bundle="ep.messages"/></c:set>
  var s = form.embedScriptPath.value;
  var embedScriptPath = s.stringTrim();
  if (embedScriptPath == "") {
    alert("<bean-el:message key="errors.required" arg0="${argName}"/>");
    return false;
  }
</c:if>
<c:if test="${epProgramPresentationForm.map.srcType == 4}">
  <c:set var="argName"><bean-el:message key="ep.program.source.type.url" bundle="ep.messages"/></c:set>
  var s = form.urlPath.value;
  var urlPath = s.stringTrim();
  if (urlPath == "") {
    alert("<bean-el:message key="errors.required" arg0="${argName}"/>");
    return false;
  }
</c:if>
  return true;
}

//
//
//
function doCancel(form) {
<c:if test="${epProgramPresentationForm.map.id == 0}">
  form.action = "<c:url value="/ep/cancel.do"/>";
</c:if>
<c:if test="${epProgramPresentationForm.map.id != 0}">
  form.action = "<c:url value="/ep/programPresentationView.do"/>";
</c:if>
  form.submit();
}

</script>

<%@include file="/mt/common/pickerPopupHelper.jsp" %>

<%@include file="/ep/file/jspScriptPickerHelper.jsp" %>

<table class="zoneFive" width="100%" border="0" cellspacing="0" cellpadding="0" summary="content area">
  <tr>
    <td valign="top" width="100%">
      <div class="pageTitle">
<c:if test="${epProgramPresentationForm.map.id == 0}">
      <bean-el:message key="ep.program.new.page.title.arg" bundle="ep.messages" arg0="${epProgramPresentationEditView.map.name}"/>
</c:if>
<c:if test="${epProgramPresentationForm.map.id != 0}">
      <bean-el:message key="ep.program.edit.page.title" bundle="ep.messages" arg0="${epProgramPresentationEditView.map.name}"/>
</c:if>
      </div>
      <div class="errorMessage"><html-el:errors bundle="ep.messages"/></div>
      <%@ include file="/mc/common/pagetab.jsp" %>

      <div class="breadcrumb">
      <c:if test="${not empty epProgramPresentationEditView.map.breadcrumbs}">
        <bean:size id="len" name="epProgramEditView" property="breadcrumbs"/>
        <c:forEach var="channel" items="${epProgramPresentationEditView.map.breadcrumbs}" varStatus="index">
          <c:url var="browseUrl" value="/ep/channelBrowse.do">
            <c:param name="channelId" value="${channel.map.id}"/>
          </c:url>
          <c:if test="${index.count > 1}"><bean-el:message key="ep.breadcrumb.delimiter" bundle="ep.messages"/>&nbsp;</c:if><c:if test="${index.count != len}"><!--a href="<c:out value="${browseUrl}"/>"--></c:if><c:out value="${channel.map.name}"/><c:if test="${index.count != len}"><!--/a--></c:if>
        </c:forEach>
      </c:if>
      </div>
      <html-el:form action="/ep/programPresentationSave.do" onsubmit="return validateForm(this)">

      <input type="hidden" name="programId" value="<c:out value="${epProgramPresentationForm.map.id}"/>"/>
      <input type="hidden" name="ctx.f" value="<c:out value="${requestScope['ctx.f']}"/>"/>
<c:if test="${epProgramPresentationForm.map.id == 0}">
      <html-el:hidden property="name"/>
      <html-el:hidden property="displayName"/>
      <html-el:hidden property="description"/>
      <html-el:hidden property="status"/>
      <html-el:hidden property="navigable"/>
      <html-el:hidden property="mgrName"/>
      <html-el:hidden property="mgrEmail"/>
  <c:forEach var="channel" items="${epProgramPresentationForm.map.parentChannels}" varStatus="index">
      <html-el:hidden property="parentChannels" value="${channel}"/>
  </c:forEach>
</c:if>
      <html-el:hidden property="primaryParentId"/>
      <input type="hidden" name="srcContentTypeChanged" value="0"/>

      <div class="pageSubtitle">
        <span class="left"><bean-el:message key="ep.program.information" bundle="ep.messages"/></span>
        <span class="right">&nbsp;
        </span>
      </div>

      <table class="labelForm" width="100%" border="0" cellspacing="0" cellpadding="0">

      <tr>
        <td class="label" width="30%"><bean-el:message key="ep.program.data.source" bundle="ep.messages"/>:</td>
        <td class="labelField" width="70%">
          <html-el:select property="srcType" onchange="onChangeSrcType()">
          <html-el:optionsCollection name="epProgramPresentationEditView" property="srcTypes"/>
          </html-el:select>
        </td>
      </tr>

<c:if test="${epProgramPresentationForm.map.srcType == 0}">
      <tr>
        <td class="label" width="30%">&nbsp;</td>
        <td class="labelField" width="70%">
          <table border="0" cellspacing="0" cellpadding="0">
          <tr>
            <td class="labelField"><bean-el:message key="ep.program.content.type" bundle="ep.messages"/>:</td>
            <td class="labelField">
              <html-el:select property="srcContentType" onchange="onChangeSrcContentType()">
              <html-el:optionsCollection name="epProgramPresentationEditView" property="contentTypes"/>
              </html-el:select>
            </td>
          </tr>
          <tr>
            <td class="labelField"> 
            <bean-el:message key="ep.program.source.type.ruleset" bundle="ep.messages"/>:*</td>
            <td class="labelField"> 
              <html-el:hidden property="srcId"/>
              <input type="text" name="srcName" size="25" value="<c:out value="${epProgramPresentationEditView.map.srcDTO.label}"/>" onfocus="this.blur()"/>&nbsp;<input type=button class="pageButton" value="<bean-el:message key="button.browse" bundle="ep.messages"/>" onclick="doRulesetSelect()">
            </td>
          </tr>
          <tr>
            <td class="labelField"> 
            <bean-el:message key="ep.program.publishing.category" bundle="ep.messages"/>:</td>
            <td class="labelField"> 
              <html-el:hidden property="publishCategoryId"/>
              <input type="text" name="publishCategoryName" size="25" value="<c:out value="${epProgramPresentationEditView.map.publishCategoryDTO.label}"/>" onfocus="this.blur()"/>&nbsp;<input type=button class="pageButton" value="<bean-el:message key="button.browse" bundle="ep.messages"/>" onclick="doPublishCategorySelect()">
            </td>
          </tr>
          <tr>
            <td class="labelField">
              <bean-el:message key="ep.program.publishing.process" bundle="ep.messages"/>:
            </td>
            <td class="labelField"> 
              <html-el:hidden property="processOID"/>
              <input type="text" name="pubProcessName" size="25" value="<c:out value="${epProgramPresentationEditView.map.publishingProcessDTO.label}"/>" onfocus="this.blur()"/>&nbsp;<input type=button class="pageButton" value="<bean-el:message key="button.browse" bundle="ep.messages"/>" onclick="doProcessSelect()">
            </td>
          </tr>
          <tr> 
            <td class="labelField" colspan="2">
              <html-el:checkbox property="showOnlyReadable"/>&nbsp;<bean-el:message key="ep.program.only.show.readable.content" bundle="ep.messages"/>
            </td>
          </tr>
          </table>
        </td>
      </tr>
</c:if>

<c:if test="${epProgramPresentationForm.map.srcType == 1 || epProgramPresentationForm.map.srcType == 6}">
      <tr>
        <td class="label" width="30%">&nbsp;</td>
        <td class="labelField" width="70%">
          <table border="0" cellspacing="0" cellpadding="0">
          <tr>
            <td class="labelField"><bean-el:message key="ep.program.content.type" bundle="ep.messages"/>:</td>
            <td class="labelField">
              <html-el:select property="srcContentType" onchange="onChangeSrcContentType()">
              <html-el:optionsCollection name="epProgramPresentationEditView" property="contentTypes"/>
              </html-el:select>
            </td>
          </tr>
          <tr>
            <td class="labelField"> 
              <bean-el:message key="ep.category" bundle="ep.messages"/>:*</td>
            <td class="labelField"> 
              <html-el:hidden property="srcId"/>
              <input type="text" name="srcName" size="25" value="<c:out value="${epProgramPresentationEditView.map.srcDTO.label}"/>" onfocus="this.blur()"/>&nbsp;<input type=button class="pageButton" value="<bean-el:message key="button.browse" bundle="ep.messages"/>" onclick="doSrcCategorySelect()">
            </td>
          </tr>

        <c:if test="${epProgramPresentationForm.map.srcContentType == 50}">
          <html-el:hidden property="processOID" value="0"/>
        </c:if>
        <c:if test="${epProgramPresentationForm.map.srcContentType != 50}">
          <tr>
            <td class="labelField">
              <bean-el:message key="ep.program.publishing.process" bundle="ep.messages"/>:
            </td>
            <td class="labelField"> 
              <html-el:hidden property="processOID"/>
              <input type="text" name="pubProcessName" size="25" value="<c:out value="${epProgramPresentationEditView.map.publishingProcessDTO.label}"/>" onfocus="this.blur()"/>&nbsp;<input type=button class="pageButton" value="<bean-el:message key="button.browse" bundle="ep.messages"/>" onclick="doProcessSelect()">
            </td>
          </tr>
        </c:if>

          <tr>
            <td class="labelField" colspan="2">
            <c:if test="${epProgramPresentationForm.map.srcType == 1}">
              <html-el:checkbox property="subCatIncluded"/>&nbsp;<bean-el:message key="ep.program.include.subcategories" bundle="ep.messages"/><br>
            </c:if>  
              <html-el:checkbox property="showOnlyReadable"/>&nbsp;<bean-el:message key="ep.program.only.show.readable.content" bundle="ep.messages"/>
            </td>
          </tr>
          </table>
        </td>
      </tr>
</c:if>

<c:if test="${epProgramPresentationForm.map.srcType == 2}">
      <tr>
        <td class="label" width="30%">&nbsp;</td>
        <td class="labelField" width="70%">
          <table border="0" cellspacing="0" cellpadding="0">
          <tr>
            <td class="labelField"><bean-el:message key="ep.program.content.type" bundle="ep.messages"/>:</td>
            <td class="labelField">
              <html-el:select property="srcContentType" onchange="onChangeSrcContentType()">
              <html-el:optionsCollection name="epProgramPresentationEditView" property="contentTypes"/>
              </html-el:select>
            </td>
          </tr>
          <tr>
            <td class="labelField"> 
              <bean-el:message key="ep.program.source.type.content" bundle="ep.messages"/>:*</td>
            <td class="labelField"> 
              <html-el:hidden property="srcId"/>
              <input type="text" name="srcName" size="25" value="<c:out value="${epProgramPresentationEditView.map.srcDTO.label}"/>" onfocus="this.blur()"/>&nbsp;<input type=button class="pageButton" value="<bean-el:message key="button.browse" bundle="ep.messages"/>" onclick="doSrcContentSelect()">
            </td>
          </tr>
          </table>
        </td>
      </tr>
</c:if>

<c:if test="${epProgramPresentationForm.map.srcType == 3}">
      <tr>
        <td class="label" width="30%">&nbsp;</td>
        <td class="labelField" width="70%">
          <table border="0" cellspacing="0" cellpadding="0">
          <tr> 
            <td class="labelField"> 
              <bean-el:message key="ep.program.page.script.path" bundle="ep.messages"/>:*</td>
            <td class="labelField"> 
              <html-el:text property="scriptPath" size="25"/>&nbsp;<input type=button class="pageButton" value="<bean-el:message key="button.browse" bundle="ep.messages"/>" onclick="selectJspPopup()">
            </td>
          </tr>
          <tr> 
            <td class="labelField"> 
              <bean-el:message key="ep.program.block.script.path" bundle="ep.messages"/>:*</td>
            <td class="labelField"> 
              <html-el:text property="embedScriptPath" size="25"/>&nbsp;<input type=button class="pageButton" value="<bean-el:message key="button.browse" bundle="ep.messages"/>" onclick="selectBlockJspPopup()">
            </td>
          </tr>
          </table>
        </td>
      </tr>
</c:if>

<c:if test="${epProgramPresentationForm.map.srcType == 4}">
      <tr>
        <td class="label" width="30%">&nbsp;</td>
        <td class="labelField" width="70%">
          <table border="0" cellspacing="0" cellpadding="0">
          <tr> 
            <td class="labelField"> 
              <bean-el:message key="ep.program.source.type.url" bundle="ep.messages"/>:*</td>
            <td class="labelField"> 
              <html-el:text property="urlPath" size="25"/>
            </td>
          </tr>
          </table>
        </td>
      </tr>
</c:if>

<c:if test="${epProgramPresentationForm.map.srcType != 3 && epProgramPresentationForm.map.srcType != 4}">
      <tr>
        <td class="label" width="30%"><bean-el:message key="ep.program.program.display.template" bundle="ep.messages"/>:</td>
        <td class="labelField" width="70%">
<c:if test="${not empty epProgramPresentationEditView.map.programDisplayTemplates}">
        <html-el:select property="programDisplayTemplateId">
          <html-el:optionsCollection name="epProgramPresentationEditView" property="programDisplayTemplates" value="id" label="name"/>
        </html-el:select>
</c:if>
        </td>
      </tr>

      <tr>
        <td class="label" width="30%"><bean-el:message key="ep.program.content.display.template" bundle="ep.messages"/>:</td>
        <td class="labelField" width="70%">
<c:if test="${not empty epProgramPresentationEditView.map.contentDisplayTemplates}">
        <html-el:select property="contentDisplayTemplateId">
          <html-el:optionsCollection name="epProgramPresentationEditView" property="contentDisplayTemplates" value="id" label="name"/>
        </html-el:select>
</c:if>
        </td>
      </tr>
</c:if>

      <tr>
        <td class="label" width="30%"><bean-el:message key="ep.program.cache.configuration" bundle="ep.messages"/>:</td>
        <td class="labelField" width="70%">
          <table cellpadding="0" cellspacing="0" border="0">
            <tr>
              <td class="labelField" colspan="2">
                <html-el:checkbox property="cacheable"/>&nbsp;<bean-el:message key="ep.program.cache.use" bundle="ep.messages"/>
              <td>
            </tr>
            <tr>
              <td class="labelField">
                <bean-el:message key="ep.program.cache.timeout" bundle="ep.messages"/>:
              </td>
              <td class="labelField">
              <html-el:text property="timeout" size="5" maxlength="10"/>&nbsp;<bean-el:message key="ep.program.cache.seconds" bundle="ep.messages"/>
              </td>
            </tr>
          </table>
        </td>
      </tr>

      </table>

      <div class="pageButtonWrap" align="right">
        <input type="reset" name="resetBtn" value="<bean-el:message key='button.reset' bundle="ep.messages"/>" class="inputButton">
        &nbsp;&nbsp;
        <input type="button" name="cancelData" class="inputButton" value="<bean-el:message key='button.cancel' bundle="ep.messages"/>" onclick="doCancel(this.form);">
        <input type="submit" name="saveData" class="inputButton" value="<bean-el:message key='button.save' bundle="ep.messages"/>">
      </div>

      </html-el:form>

    </td>
  </tr>
</table>
